<?php
/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2017/10/18
 * Time: 16:48
 */

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use DB;
use View;

use App\Http\Controllers\Logistics\KdNiaoController as KdNiao;
use App\Http\Controllers\Pay\PingPayController as PingPay;
use App\Http\Controllers\Pay\AliPayController as AliPay;
use App\Http\Controllers\Pay\AliDirectPayController as AliDirectPay;
use App\Model\AatestOrder;

class AddDataBasesController extends Controller
{
    /**
     * @return string
     */
    public function addDatas($num)
    {
        for($i=0;$i<=$num;$i++){
           $data = [
                'user_name'=> $this->randomchar(9,0),
                'user_phone'=> '15010088584',
                'user_content'=> $this->randomchar(50,0),
                'user_email'=> '645627198@qq.com',
                'add_time'=> rand(1470000000,1488046000),
                'add_ip'=> '127.0.0.1',
           ];

           DB::table('feedback')->insert($data);
       }
    }

    public function orderList()
    {
        $order_list = AatestOrder::get()->toArray();
        $order_json = json_encode($order_list);
        return View::make('testview.testorder',['orderlist'=>$order_json]);
    }

    /**
     * 模拟写入订单
     */
    public function insertOrder(Request $request)
    {
        $data['kdn_company_code'] = 'EMS';
        $data['kdn_logistics_num'] = $request->get('content');
        $id = $request->get('id');
        DB::table('logistics_callback')->where('id',$id)->update($data);
        $kd_obj = new KdNiao();
        $res = $kd_obj->getTrack($data['kdn_company_code'],$data['kdn_logistics_num']);
        $jsonData = $res ? $this->getJsonData(2,'添加快递成功') : $this->getJsonData(0,'添加快递失败');
        return response()->json($jsonData);
    }

    public function orderPay(){
        $order_data = [
            'subject'=>'测试数据Sub001',
            'body'=>'测试数据Body001',
            'amount'=>'1',
            'order_no'=>'TEST'.time().'001',
            'channel'=>'alipay_pc_direct',
        ];
        $pay_obj = new PingPay();
        $charge = $pay_obj->payapi($order_data);
        return view('pingpay.pay',['charge'=>$charge]);
    }

    public function orderAliPay(){
        $order_data = [
            'subject'=>'测试数据Sub001',
            'body'=>'测试数据Body001',
            'total_amount'=>'0.03',
            'out_trade_no'=>'TEST'.time().'001',
        ];
        $pay_obj = new AliPay();
        $charge = $pay_obj->aliWapPay($order_data);
        return $charge;
    }

    public function orderAliDirectPay(){
        $order_data = [
            'subject'=>'测试数据Direct001',
            'body'=>'测试数据DirectBody001',
            'total_fee'=>'0.01',
            'showurl'=>'',
            'out_trade_no'=>'TEST'.time().'002',
        ];
        $pay_obj = new AliDirectPay();
        $charge = $pay_obj->aliDirectPay($order_data);
        return $charge;
    }

    public function paySuccess()
    {
        return '支付成功';
    }
}